<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8"/>
    <title>table模块快速使用</title>
    <link rel="stylesheet" th:href="@{/static/layui/css/layui.css}" media="all"/>
    <link rel="stylesheet" th:href="@{/static/viewer/viewer.css}"/>

    <script th:src="@{/static/js/jquery.min.js}"></script>
    <script th:src="@{/static/layui/layui.js}"></script>
    <script th:src="@{/static/layui/wk.js}"></script>
    <script th:src="@{/static/viewer/viewer.js}"></script>

</head>

<body>


<div class="layui-form layui-form-pane" style="margin: 5px">
    <button class="layui-btn" id="add" lay-even="add">添加</button>
</div>

<div class="layui-form">
    <table class="layui-table">
        <colgroup>
            <col width="240"/>
            <col width="240"/>
            <col/>
            <col/>
            <col/>
            <col/>
        </colgroup>
        <thead>
        <tr>
            <th>权限名称</th>
            <th>跳转链接</th>
            <th>上级权限名称</th>
            <th>排序</th>
            <th>跳转类型</th>
            <th>操作栏</th>
        </tr>
        </thead>
        <tbody>
            <span th:each="aclListVo : ${list}">
                <tr>
                    <td th:text="${aclListVo.urlName}"></td>
                    <td th:text="${aclListVo.url}"></td>
                    <td th:text="${aclListVo.parentName}"></td>
                    <td th:text="${aclListVo.sort}"></td>
                    <td th:text="${aclListVo.urlType}==1?'菜单':'按钮'"></td>
                    <td>
                        <button class="layui-btn layui-btn-sm layui-btn-normal" th:data-thing = "${aclListVo.aclId}"  onclick = "update(this.getAttribute('data-thing'));">编辑</button>
                        <button class="layui-btn layui-btn-sm layui-btn-normal" th:data-thing = "${aclListVo.aclId}"  onclick = "del(this.getAttribute('data-thing'));">删除</button>
                    </td>
                </tr>
                <span th:each="aclListVo2 : ${aclListVo.list}">
                <tr>
                    <td th:text="'｜--'+${aclListVo2.urlName}"></td>
                    <td th:text="${aclListVo2.url}"></td>
                    <td th:text="${aclListVo2.parentName}"></td>
                    <td th:text="${aclListVo2.sort}"></td>
                    <td th:text="${aclListVo2.urlType==1?'菜单':'按钮'}"></td>
                    <td>
                        <button class="layui-btn layui-btn-sm layui-btn-normal" th:data-thing = "${aclListVo2.aclId}"  onclick = "update(this.getAttribute('data-thing'));">编辑</button>
                        <button class="layui-btn layui-btn-sm layui-btn-normal" th:data-thing = "${aclListVo2.aclId}"  onclick = "del(this.getAttribute('data-thing'));">删除</button>
                    </td>
                </tr>
                <tr th:each="aclListVo3 : ${aclListVo2.list}">
                    <td th:text="'&nbsp;&nbsp;&nbsp;&nbsp;｜--｜--'+${aclListVo3.urlName}"></td>
                    <td th:text="${aclListVo3.url}"></td>
                    <td th:text="${aclListVo3.parentName}"></td>
                    <td th:text="${aclListVo3.sort}"></td>
                    <td th:text="${aclListVo3.urlType==1?'菜单':'按钮'}"></td>
                    <td>
                        <button class="layui-btn layui-btn-sm layui-btn-normal" th:data-thing = "${aclListVo3.aclId}"  onclick = "update(this.getAttribute('data-thing'));">编辑</button>
                        <button class="layui-btn layui-btn-sm layui-btn-normal" th:data-thing = "${aclListVo3.aclId}"  onclick = "del(this.getAttribute('data-thing'));">删除</button>
                    </td>
                </tr>
                </span>
            </span>
        </tbody>
    </table>
</div>

</body>

<script th:inline="none">
    layui.use(['util','jquery', 'layer', 'table'], function () {

        var table = layui.table;

        //让层自适应iframe
        $('#add').on('click', function(){
            var index = layer.open({
                type: 2,
                content: '/bg/dicAcl/toAdd',
                area: ['400px', '450px'],
                maxmin: true,
                end: function () {
                    location.reload();
                }
            });
            parent.layer.iframeAuto(index);
        });
    });


    // 删除
    function del(id){
        layer.confirm('删除后无法复原，真的删除行么？', function(index){
            $.ajax({
                url : '/bg/dicAcl/del',
                type : 'post',
                dataType : 'json',
                data : {aclId : id},
                success : function (data) {
                    if (data.code=="200"){
                        layer.msg(data.msg,{icon: 1, time: 500},function () {
                            window.location.reload();
                        });
                    }else{
                        layer.msg(data.msg,{icon: 1, time: 1000});
                    }
                }
            })

        });
    };

    // 修改
    function update(id){
        var index = layer.open({
            type: 2,
            content: '/bg/dicAcl/toEdit?aclId='+id,
            area: ['400px', '450px'],
            maxmin: true,
            end: function () {
                location.reload();
            }
        });
        parent.layer.iframeAuto(index);
    };

</script>
</html>
